import numpy as np

# 模拟图像处理
# 创建简单的8*8的黑白图像(0=黑色，1=白色)
image = np.zeros((8,8),dtype=np.int16)
image[2:6,2:6] = 255
print("原始图像:\n", image)

# 图像反转
flipped_img = np.flipud(image)
print("旋转90度后::\n", flipped_img)

# 边缘检测基础 (简化版)
# 使用简单的差分方法检测边缘
edges = np.zeros_like(image)

edges[1:-1, 1:-1] = np.abs(image[2:, 1:-1] - image[:-2, 1:-1]) + \
                    np.abs(image[1:-1, 2:] - image[1:-1, :-2])
print("\n边缘检测结果:")
print(edges)

import numpy as np

# 创建一个简单的示例图像来演示边缘检测原理
# 这个图像左边是黑色(0)，右边是白色(255)
demo_image = np.zeros((5, 10), dtype=np.uint8)
demo_image[:, 5:] = 255  # 右半部分设为白色

print("示例图像:")
print(demo_image)

# 水平方向差分 - 检测垂直边缘
# 计算每个像素与其右侧像素的差值
horizontal_diff = np.zeros_like(demo_image)
horizontal_diff[:, :-1] = np.abs(demo_image[:, 1:] - demo_image[:, :-1])

print("\n水平方向差分(检测垂直边缘):")
print(horizontal_diff)

# 垂直方向差分 - 检测水平边缘
# 计算每个像素与其下方像素的差值
vertical_diff = np.zeros_like(demo_image)
vertical_diff[:-1, :] = np.abs(demo_image[1:, :] - demo_image[:-1, :])

print("\n垂直方向差分(检测水平边缘):")
print(vertical_diff)

# 综合边缘检测 - 同时考虑水平和垂直方向的变化
combined_edges = horizontal_diff + vertical_diff
print("\n综合边缘检测:")
print(combined_edges)
